package com.taosdata.example.mybatisplus.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.taosdata.example.mybatisplus.domain.Temperature;
import org.apache.ibatis.annotations.*;

import java.util.Map;

/**
 * @author PC
 */
public interface TemperatureMapper extends BaseMapper<Temperature> {
    @Update("CREATE STABLE if not exists temperature(ts timestamp, temperature float) tags(location nchar(64), tbIndex int)")
    int createSuperTable();

    @Update("create table #{tbName} using temperature tags( #{location}, #{tbindex})")
    int createTable(@Param("tbName") String tbName, @Param("location") String location, @Param("tbindex") int tbindex);

    @Update("drop table if exists temperature")
    void dropSuperTable();

    @Insert("insert into t${tbIndex}(ts, temperature) values(#{ts}, #{temperature})")
    int insertOne(Temperature one);

    @Select("select * from t0 order by ts desc limit 1")
    Temperature selectLastRow1();

    @Select("select * from t0 order by ts desc limit 1")
    Map<String, Object> selectLastRow1_1();

    @Select("select * from t0 order by ts desc limit 1")
    Object selectLastRow1_2();

    // ts,temperature,location
    @Select("select last_row(*) from t0")
    Temperature selectLastRow2();

    @Select("select last_row(*) from t0")
    Map<String, Object> selectLastRow2_1();

    @Select("select last_row(*) from t0")
    Object selectLastRow2_2();

    /*@Select("select last_row(*) from temperature where location=#{location}")
    Temperature selectLastRow4(@Param("location") String location);*/
}
